#ifndef SYNCCONTROLLER_H
#define SYNCCONTROLLER_H

#include <QObject>
#include "dao/dao.h"
#include "services/genericservice.h"
#include "entity/aqfornecedor.h"

#define MAIN_URL "http://192.168.25.2:8081"

class SyncController : public QObject
{
    Q_OBJECT
public:
    explicit SyncController(QObject *parent = 0);
    void startSync();

    Q_INVOKABLE QVariantList loadFornecedores();
    Q_INVOKABLE void updatePos(QString id, QString lat, QString lon);

signals:
    void loadComplete();
    void loadError();

//    void updateComplete();
//    void updateError();

    void sendComplete();
    void sendError();

public slots:
    void AQFornecedorReceived(const QByteArray &response);
    void AQFornecedorError(QNetworkReply::NetworkError err);

    void UpdatePosReceived(const QByteArray &response);
    void UpdatePosError(QNetworkReply::NetworkError err);

private:
    template<class T>
    bool importCSV(T *dao, QString response, QString nomeEntidade);
    template<class T>
    bool postCSV(T *daoEntidade, GenericService &genericService, QString nomeEntidade, QString where = QString());
    QString getMacAddress();

    AQFornecedor *fornecedorSincronizando;
    Service service;

    GenericService serviceAQFornecedor;
    GenericService serviceUpdatePos;
};

#endif // SYNCCONTROLLER_H
